package com.jic.product.controller.manage;

import com.jic.common.base.vo.RestResult;
import com.jic.product.common.util.BeanUtil;
import com.jic.product.entity.ProductUnitsRelation;
import com.jic.product.manage.request.ProductUnitsRelationRequest;
import com.jic.product.manage.response.ProductUnitsRelationResponse;
import com.jic.product.service.ProductUnitsRelationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/ProductUnitsRelation")
@Api(value = "计量单位关联表controller", tags = {"计量单位关联接口"})
public class ProductUnitsRelationController {

    @Autowired
    ProductUnitsRelationService productUnitsRelationService;

    @ApiOperation(value = "获取计量单位关联")
    @GetMapping("/query")
    public RestResult<List<ProductUnitsRelationResponse>> query(@RequestParam(value = "productId") long productId) {
        List<ProductUnitsRelationResponse> result = productUnitsRelationService.query(productId);
        return RestResult.success(result);
    }

    @ApiOperation(value = "修改获取计量单位关联")
    @PostMapping("/update")
    public RestResult<String> update(@RequestBody ProductUnitsRelationRequest form) {
        // 请求实体转数据库实体
        ProductUnitsRelation productUnitsRelation = BeanUtil.copy(form, ProductUnitsRelation.class);
        return productUnitsRelationService.update(productUnitsRelation);
    }

    @ApiOperation(value = "新增获取计量单位关联")
    @PostMapping(value = "/insert")
    public RestResult<String> insert(@RequestBody ProductUnitsRelationRequest form) {
        // 请求实体转数据库实体
        ProductUnitsRelation productUnitsRelation = BeanUtil.copy(form, ProductUnitsRelation.class);
        return productUnitsRelationService.insert(productUnitsRelation);
    }


}
